package Widget

import (
	"github.com/lxn/walk/declarative"
)

type XButton struct {
	Sprite *declarative.Composite
	Button *declarative.PushButton
}

func (m *XButton) SetButtonText(txt string) {
	if m.Button == nil {
		return
	}
	m.Button.Text = txt
}

func (m *XButton) SetButtonFunc(cb func()) {
	if m.Button == nil {
		return
	}
	m.Button.OnClicked = cb
}

func CreateButton() *XButton {
	b := &XButton{
		Sprite: &Composite{
			Layout: declarative.HBox{},
			Children: []declarative.Widget{
				&declarative.PushButton{
					Text:    "测试按钮",
					MaxSize: declarative.Size{Width: 50, Height: 40},
					//OnClicked: cb,
				},
			},
		},
	}
	tmp := b.Sprite.Children[0]
	if _, ok := tmp.(*declarative.PushButton); ok {
		b.Button = tmp.(*declarative.PushButton)
	} else {
		// 处理类型断言失败的情况
		// 比如输出错误日志或执行其他逻辑
	}
	return b
}
